import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

export default new Router({
  routes: [{
      path: '/index',
      name: 'index',
      component: () => import('@/views/index.vue'),
      // 子路由
      children: [{
          path: '/userlist',
          name: 'userlist',
          component: () => import('@/components/user/userlist.vue')
        },
        {
          path: '/rolelist',
          name: 'rolelist',
          component: () => import('@/components/role/rolelist.vue')
        },
        {
          path: '/rightlist',
          name: 'rightlist',
          component: () => import('@/components/role/rightlist.vue')
        },
        {
          path: '/goodslist',
          name: 'goodslist',
          component: () => import('@/components/goods/goodslist.vue')
        },
        {
          path: '/sortparameter',
          name: 'sortparameter',
          component: () => import('@/components/goods/sortparameter.vue')
        },
        {
          path: '/goodssort',
          name: 'goodssort',
          component: () => import('@/components/goods/goodssort.vue')
        },
        {
          path: '/orderlist',
          name: 'orderlist',
          component: () => import('@/components/order/orderlist.vue')
        },
        {
          path: '/datareport',
          name: 'datareport',
          component: () => import('@/components/datareport/datareport.vue')
        },
        {
          path: '/userlist',
          redirect: '/userlist'
        }
      ],
      //登陆鉴权
      beforeEnter: (to, from, next) => {
        if (sessionStorage.getItem('token')) {
          next();
        } else {
          alert('请先登录')
          next('/login')
        }
      }
    },
    {
      path: '/',
      redirect: 'index'
    },
    {
      path: '/login',
      name: 'login',
      component: () => import('@/views/login.vue')
    }
  ]
})